package com.exam.util;

import com.exam.entity.sys.SysUser;
import org.apache.commons.lang.StringUtils;

import java.lang.reflect.Field;

public class TestEntity {
    public static boolean checkObjAllFieldsIsNull(Object object) {
        if (null == object) {
            return true;
        }

        try {
            for (Field f : object.getClass().getDeclaredFields()) {
                f.setAccessible(true);

                System.out.print(f.getName() + ":");
                System.out.println(f.get(object));

                if (f.get(object) != null && StringUtils.isNotBlank(f.get(object).toString())) {
                    return false;
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return true;
    }

    public static void main(String[] args) {
        SysUser user1 = new SysUser();
        user1.setU_id(1);
        user1.setA_id(1);
        SysUser user2 = new SysUser();

        System.out.println(user1.getU_name()==null);
        System.out.println(user2.toString());

        boolean u1Flag = checkObjAllFieldsIsNull(user1);
        boolean u2Flag = checkObjAllFieldsIsNull(user2);

        System.out.println("user1 是否为空：" + u1Flag);
        System.out.println("user2 是否为空：" + u2Flag);

    }
}
